package cn.swu.lzr.event;

import cn.swu.lzr.JDBC.DBTools;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.util.List;

public class SearchServlet extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
        String type = request.getParameter("type");
        String key  = request.getParameter("key");
        try {
            DBTools dbTools = new DBTools();
            List<Event> events =  dbTools.SearchBy(type,key);

            System.out.println(events);

            HttpSession session = request.getSession();
            session.setAttribute("SearchType",events);


            response.sendRedirect("NewSearch.html");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
